<template>

  <!--
          作者：luoyiming
          时间：2019-10-25
          描述：门店-店员列表
      -->
  <div class="user clearfix">

    <!--添加门店-->
    <div class="common-level-rail fl">
      <el-button size="small" type="primary" icon="Plus" @click="addClick" v-auth="'/store/clerk/add'">新增店員</el-button>
    </div>
    <div class="common-seach-wrap fr">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="">
          <el-select v-model="formInline.storeId" placeholder="所屬門市">
            <el-option label="全部" value="0"></el-option>
            <el-option v-for="(item,index) in storeList" :key="index" :label="item.storeName" :value="item.storeId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-input v-model="formInline.search" placeholder="請輸入店員姓名/手機號碼"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search" @click="onSubmit">查詢</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="clerkId" label="門市ID" width="60"></el-table-column>
          <el-table-column prop="avatarurl" label="微信頭像" width="70">
            <template #default="scope">
              <img v-if="scope.row" v-img-url="scope.row.avatarUrl" width="30" height="30" />
            </template>
          </el-table-column>
          <el-table-column prop="nickName" label="微信暱稱"></el-table-column>
          <el-table-column prop="storeName" label="所屬門市"></el-table-column>
          <el-table-column prop="realName" label="店員姓名"></el-table-column>
          <el-table-column prop="mobile" label="店員手機號碼"></el-table-column>
          <el-table-column prop="statusText" label="狀態">
            <template #default="scope">
              <span :class="{green:scope.row.status==1,gray:scope.row.status==0}">{{scope.row.statusText}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="新增時間"></el-table-column>
          <el-table-column fixed="right" label="操作" width="120">
            <template #default="scope">
              <el-button @click="editClick(scope.row)" type="text" size="small" v-auth="'/store/clerk/edit'">編輯</el-button>
              <el-button @click="deleteClick(scope.row.clerkId)" type="text" size="small" v-auth="'/store/clerk/delete'">刪除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="curPage"
          :page-size="pageSize" layout="total, prev, pager, next, jumper"
          :total="totalDataNumber">
        </el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
import StoreApi from '@/api/store.js';
export default {
  components: {},
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*门店列表数据*/
      storeList: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        shop_id: '',
        search: ''
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {}
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
    this.getStoreList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {};
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      StoreApi.clerklist(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
        //self.storeList = res.data.store_list.data;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*获取列表*/
    getStoreList() {
      let self = this;
      let Params = {};
      StoreApi.toAddClerk(Params, true).then(res => {
        self.loading = false;
        self.storeList = res.data;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*搜索查询*/
    onSubmit() {
      let self = this;
      self.loading = true;
      let Params = this.formInline;
      StoreApi.clerklist(Params, true).then(data => {
        self.loading = false;
        self.tableData = data.data.records;
        self.totalDataNumber = data.data.total;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*打开添加*/
    addClick() {
      this.$router.push('/store/clerk/add');
    },
    /*打开编辑*/
    editClick(row) {
      let self = this;
      let params = row.clerkId;
      this.$router.push({
        path: '/store/clerk/edit',
        // name: 'mallList',
        query: {
          clerkId: params
        }
      });
    },
    /*删除*/
    deleteClick(row) {
      let self = this;
      ElMessageBox.confirm("此操作將永久刪除該筆記錄，是否繼續？", "提示", {
        confirmButtonText: "確定",
        cancelButtonText: "取消",
        type: 'warning'
      }).then(() => {
        self.loading = true;
        StoreApi.deleteClerk({
          clerkId: row
        }, true).then(data => {
          self.loading = false;
          if (data.code == 1) {
            ElMessage({
              message: "恭喜您，店員刪除成功",
              type: 'success'
            });
            self.getTableList();
          }
        }).catch(error => {
          self.loading = false;
        });
      }).catch(() => {
        self.loading = false;
      });
    }
  }
};
</script>

